<%-- 
    Document   : footer
    Created on : Sep 21, 2012, 8:28:46 AM
    Author     : DucThien
--%>

<div id="line-footer" class="frameWidth"></div>
        <div class="frameWidth" id="footer">
            <div id="footer-bottom">
               
                <div id="menu-bottom">
                    <ul>
                        <li onclick="countDownDeal();">Home</li>|
                        <li>Special</li>|
                        <li>Account</li>|
                        <li>Check Out</li>|
                        <li>Contact Us</li>
                    </ul>
                </div>
            </div>
        </div>
 
    <script type="text/javascript">
    $("#middle_content_bottom").load("./deal?action=pagination",function(){
        countDownDeal();
    });
    $("#deal_top").load("./deal?action=view_detail&deal_id=1&deal_top=1",function(){
        countDownDeal();
    });
    function countDownDeal(){
        var austDay = new Date();
        $(".count_down").each(function (){
            var id = this.id;
            var date = this.title;
            var value = date.split("-");
            var year = parseInt(value[0]);
            var month = parseInt(value[1]);
            var day = parseInt(value[2]);
            austDay = new Date(year,month,day,0,0,0);
            $("#"+id).countdown({until: austDay});
        });   
    }   
    $('#middle_content_bottom .pagination-deal a').live('click', function() {
	$('#middle_content_bottom').load(this.href,function(){
            countDownDeal();
        });
        //countDown();	
	return false;
    });	
    
    function filterListDeal(){
        var dealName = $("#search_deal_name").val() == "" ? "" : $("#search_deal_name").val();
        var dealerName = $("#search_dealer_name").val() == "" ? "" : $("#search_dealer_name").val();
        var percentDiscount = ($("#search_percent_discount").val() == "" || $("#search_percent_discount").val() <= 0) ? "-1" : $("#search_percent_discount").val();
        var dealerAddress = $("#search_dealer_address").val() == "" ? "" : $("#search_dealer_address").val() ;
        var fromCost = ($("#search_from_cost").val() == "" || $("#search_from_cost").val() <= 0) ? "-1" : $("#search_from_cost").val();
        var toCost = ($("#search_to_cost").val() == "" || $("#search_to_cost").val() <= 0) ? "-1" : $("#search_to_cost").val();
        var url = "&dealName="+encodeURIComponent(dealName)+"&dealerName="+encodeURIComponent(dealerName)+"&percentDiscount="+percentDiscount+"&dealerAddress="+encodeURIComponent(dealerAddress)+"&fromCost="+fromCost+"&toCost="+toCost;
        
        $("#middle_content_bottom").load("./deal?action=filterListDeal"+url,function(){
            countDownDeal();
        });
        return false;
    }
    
    function filterListDealAll(){
        $("#form-search-deal").resetForm();
        $("#middle_content_bottom").load("./deal?action=pagination");
        return false;
    }
    var xmlhttp = new getXMLObject();
    
    function CheckUsername(username,password){         
       
        xmlhttp.open("POST","login",true); //getname will be the servlet name
        xmlhttp.onreadystatechange  = handleServerResponse;
        xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlhttp.send("username=" + username +"&password="+ password); //Posting txtname to Servlet
        
    }
    function CheckEmailExists(email){
        $.post("./registration",{check_email:email}, function(data){
            if(data == "false"){
                return true;
            }else{
                return false;
            }
            //alert(data);
        });
    }
    function handleServerResponseRegistration(){
        if (xmlhttp.readyState == 4) {
            if(xmlhttp.status == 200) {               
                var resultResponse = $.trim(xmlhttp.responseText.toString());
                if(resultResponse == "true"){
                   // alert('here.........................')
                   return false;
                }else{
                  //  alert('error.........................')
                    return true
                }
                
            }
            else {
                alert("Error during AJAX call. Please try again");
            }
        }
    }
    function handleServerResponse() {       
        if (xmlhttp.readyState == 4) {
            if(xmlhttp.status == 200) {               
                var resultResponse = $.trim(xmlhttp.responseText.toString());
                if(resultResponse == "success"){
                   // alert('here.........................')
                    $("#error_login").text("");
                    $("#login_dialog").dialog("close");
                    window.location = 'deal';
                }else{
                  //  alert('error.........................')
                    $("#error_login").text("username or password is not match .");
                }
                
            }
            else {
                alert("Error during AJAX call. Please try again");
            }
        }
    }
    
    function getXMLObject()  //XML OBJECT
    {
        var xmlHttp = false;
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");  // For Old Microsoft Browsers
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  // For Microsoft IE 6.0+
            }
            catch (e2) {
                xmlHttp = false ;  // No Browser accepts the XMLHTTP Object then false
            }
        }
        if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
            xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
        }
        return xmlHttp;  // Mandatory Statement returning the ajax object created
    }

    function showDialogLogin(){
         if($('#editor').length == 0){
	       $('#editor').dialog("destroy");
	       $('#editor').remove();
         }
         $("#login_dialog").dialog({
                bgiframe:false,
                width:'auto',
                height:'auto',
		modal:true,
                show: "blind",
                hide: "blind",
		buttons:{
                   'cancel':function (){
                        $(this).dialog('close');
                   },
                   'Login':function(){ // button ok
                        $("#error_login").text("");
                        var username = $("input[name='username']").val();
                        var password = $("input[name='password']").val();
                        CheckUsername(username,password);
                   }
                }
            });
    }

    function showDialogRegistration(){
        if($("#login_dialog").length){
            $("#login_dialog").dialog("close");
        }
        $("#registration_dialog").dialog({
                bgiframe:false,
                width:'auto',
                height:'auto',
		modal:true,
                show: "blind",
                open: function(){
                    $("#registration_dialog table tbody > tr > td span").empty();
                    $("#registration_dialog table tbody > tr > td input").val('');
                    $("#registration_dialog .require").append("<span style='color:red;'>*</span>");
                },
                hide: "blind",
		buttons:{
                   'cancel':function (){
                        $("#registration_dialog table tbody > tr > td input").val('');
                        $(this).dialog('close');
                   },
                   'Registration':function(){ // button ok
                        $("#registration_dialog table tbody > tr > td span").empty();
                        if(checkRegistration()){
                            // make registration
                             $.post("./registration",$('#form-registration').serialize(), function(data){                              
                                 if(data == "true"){
                                     $(this).dialog('close');
                                 }else{
                                     alert("add new customer fail ........................");
                                     return false;
                                 }
                             });
                        }else{
                            return false;
                        }
                   }
                }
            });
    }
    
   
       
    </script>
    <script type="text/javascript">
        function showDealDetail(id){         
            if($('#editor').length == 0){
	       $('#editor').dialog("destroy");
	       $('#editor').remove();
            }
            $('#container').prepend('<div id="editor" style="padding: 3px 0px 0px 0px; "><iframe src="./deal?action=view_detail&deal_id='+id+'" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');

            $('#editor').dialog({
                title: 'Deal Detail',
                buttons: {
                    "Save": function() {
                    },
                    "Close": function(){
                        $(this).dialog('close');
                        $(this).remove();
                    }
                },
                close: function(){
                    $('.frameWidth').css('width','960px');
                    $('#content').css('height','auto');
                    
                    $(this).dialog('close');
                    $(this).remove();
                },
                bgiframe: false,
                width: 960,
                height: 1000,
                resizable: false,        
                modal: true,
                position:"top",
                show: "blind",
                hide: "blind",
                open: function(){
                    
                    $('.ui-widget-content').css('cursor','move');
                    $('.ui-widget-content').css('background','none');
                    $('.ui-widget-content').css('background-color','#FFFFFF');
                    $('.frameWidth').css('width','960px');
                    $('.ui-widget-header').css('background','none');
                    $('.ui-widget-header').css('border','1px solid #CCCCCC');
                    $('.ui-widget-header').css('background-color','#9E9797');
                    $('.ui-dialog-buttonpane').css('display','none');
                    
                }      
            });
           
        }
    </script>
    <script type="text/javascript">
        var checkRegistration = function(){
            var error_UserName = $("#error_username");
            var error_Password = $("#error_password");
            var error_PasswordConfirm = $("#error_passwordConfirm");
            var error_Name = $("#error_name");
            var error_IdentityCard = $("#error_identityCard");
            var error_NumberPhone = $("#error_numberPhone");
            var error_Email = $("#error_email");
            var error_Address = $("#error_address");
            var error_DOB = $("#error_DOB");
            
            var val_UserName = $("#user_name").val();
            var val_Password = $("#pass").val();
            var val_PasswordConfirm = $("#passConfirm").val();
            var val_Name = $("#name").val();
            var val_IdentityCard = $("#identity_card").val();
            var val_NumberPhone = $("#number_phone").val();
            var val_Email = $("#email").val();
            var val_Address = $("#address").val();
            var val_DOB = $("#DOB").val();
            
            // start check
            var boolean_registration = true;
            if(!val_UserName){
                error_UserName.prepend("*username is required !");
                boolean_registration = false;
            }else{
                error_UserName.empty();
            }
            
            if(!val_Password){
                error_Password.prepend("*password is required !");
                boolean_registration = false;
            }else{
                error_UserName.empty();
            }
            
            if(!val_PasswordConfirm){
                error_PasswordConfirm.prepend("*password Confirm is required !");
                boolean_registration = false;
            }else{
                error_UserName.empty();
            }
            
            if(!val_Name){
                error_Name.prepend("*Customer name is required !");
                boolean_registration = false;
            }else{
                error_Name.empty();
            }
            
            if(!val_IdentityCard){
                error_IdentityCard.prepend("*identity card is required !");
                boolean_registration = false;
            }else{
                error_IdentityCard.empty();
            }
            
            if(!val_NumberPhone){
                error_NumberPhone.prepend("*number phone is required !");
                boolean_registration = false;
            }else{
                error_NumberPhone.empty();
            }
            
            if(!val_Email){
                error_Email.prepend("*Email is required !");
                boolean_registration = false;
            }else if(!validateEmail(val_Email)){
                error_Email.prepend("*Email is not available !");
                boolean_registration = false;
            }else if(CheckEmailExists(val_Email)){
                error_Email.prepend("*Email Exists !!! ");
                boolean_registration = false;
            }else{
                error_Email.empty();
            }
            
            if(!val_Address){
                error_Address.prepend("*Address is required !");
                boolean_registration = false;
            }else{
                error_Address.empty();
            }
            
            if(!val_DOB){
                error_DOB.prepend("*Birthday is required !");
                boolean_registration = false;
            }else{
                error_DOB.empty();
            }
            return boolean_registration;
        }
        var validateEmail = function (email) {
			var at = email.lastIndexOf("@");

			// Make sure the at (@) sybmol exists and  
			// it is not the first or last character
			if (at < 1 || (at + 1) === email.length)
				return false;

			// Make sure there aren't multiple periods together
			if (/(\.{2,})/.test(email))
				return false;

			// Break up the local and domain portions
			var local = email.substring(0, at);
			var domain = email.substring(at + 1);

			// Check lengths
			if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
				return false;

			// Make sure local and domain don't start with or end with a period
			if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
				return false;

			// Check for quoted-string addresses
			// Since almost anything is allowed in a quoted-string address,
			// we're just going to let them go through
			if (!/^"(.+)"$/.test(local)) {
				// It's a dot-string address...check for valid characters
				if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
					return false;
			}

			// Make sure domain contains only valid characters and at least one period
			if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
				return false;	

			return true;
		}
       var available = function(evt,typeFloat){
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if (typeFloat == false && charCode != 37 && charCode != 39 && charCode > 31 && (charCode < 48 || charCode > 57))
            {   return false; }
            else if(typeFloat == true && charCode != 37 && charCode != 39 && charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
            {   return false; }
            return true;
        }
    </script>
    
    </div>
   